<template>
    <div v-loading="loading" ref="iframeContent" style="height: 100%;">
    </div>
</template>
<script>
import { login_key, current_menu_info, custom_router_path } from "@/config/storage-keys";
// import MenuConfig from '@/config/menu-config'
export default {
    key: "custom-iframe",
    title: "自定义菜单地址",
    path: custom_router_path,
    data() {
        return {
            iframeSrc: '',
            loading: false
        };
    },
    watch: {
        $route: {
            handler: function() {
                const customInfo = this.$Storage.getSessionStorage(current_menu_info)
                const userInfo = this.$Storage.getLocalStorage(login_key) || {};
                if(customInfo && customInfo.path === custom_router_path) {
                    if(customInfo.iframeSrc) {
                        this.iframeSrc = customInfo.iframeSrc
                    }else {
                        this.iframeSrc = userInfo.dept && userInfo.dept.deptShowUrl || ''
                    }
                }
                const iframe = document.createElement('iframe')
                iframe.src = this.iframeSrc
                iframe.frameborder = "0"
                iframe.width = "100%"
                iframe.height = "100%"
                this.$nextTick(()=>{
                    const dom = this.$refs.iframeContent
                    if(dom) {
                        dom.innerHTML = ""
                        dom.appendChild(iframe)
                        // 启动loading加载效果
                        this.loading = true
                        iframe.addEventListener("load", () => {
                            this.loading = false
                        },false)
                    }
                })
            },
            immediate: true
        }
    }
};
</script>
